import 'dart:developer';

import 'package:bruno/bruno.dart';
import 'package:demo_flutter/api/itemApi.dart';
import 'package:demo_flutter/common/vo/items.dart';
import 'package:flutter/material.dart';

class ItemClockEvent extends StatefulWidget {
  final int? id;
  const ItemClockEvent({Key? key, required this.id}) : super(key: key);

  @override
  _ItemClockEventState createState() => _ItemClockEventState();
}

class _ItemClockEventState extends State<ItemClockEvent> {
  @override
  Widget build(BuildContext context) {
    print(widget.id);
    // 根据id获取
    if (widget.id != null) {
      Future f = ItemApi().getItemById(widget.id);
      f.then((response) {
        Item a = response;
        log(a.name);
      });
    }

    // 周几打卡
    List<bool> days = [false, false, false, false, false, false, false];
    String jobName = "";

    return Scaffold(
      appBar: BrnAppBar(
        automaticallyImplyLeading: true,
        title: '编辑物品',
        actions: BrnTextAction(
          '保存',
          //设置为深色背景，则显示白色
          themeData: BrnAppBarConfig.dark(),
          iconPressed: () {
            // TODO 点击了保存
            print(jobName);
            print(days);
          },
        ),
      ),
      body: ListView(
        scrollDirection: Axis.vertical,
        children: [
          BrnInputText(
            hint: "任务名称",
            padding: const EdgeInsets.all(15),
            maxLength: 20,
            onTextChange: (input) => jobName = input,
          ),
          BrnTextQuickSelectFormItem(
              title: "打卡日期",
              btnsTxt: const ["周一", "周二", "周三", "周四", "周五", "周六", "周日"],
              value: "",
              isBtnsScroll: true,
              onBtnSelectChanged: (value) {
                bool isTrue = days[value];
                if (isTrue) {
                  days[value] = false;
                } else {
                  days[value] = true;
                }
              })
        ],
      ),
    );
  }
}
